﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Net.NetworkInformation;

namespace BkXitiTagger.Util
{
    /// <summary>
    /// The type of data connection
    /// </summary>
    public enum MobileConnectionType
    {
        WiMax,
        ThreeG,
        Wwan,
        Wifi,
        Unknown = 0
    }

    /// <summary>
    /// Provide information about the data connection
    /// </summary>
    public class ConnectionInformation
    {
        /// <summary>
        /// Flag indicating usage of Wifi
        /// </summary>
        public static bool IsWifiEnabled
        {
            get
            {
                return NetworkInterface.NetworkInterfaceType == NetworkInterfaceType.Wireless80211;
            }
        }

        /// <summary>
        /// Flag indicating usage of mobile broadband data connection
        /// </summary>
        public static bool IsMobileBroadbandEnabled
        {
            get
            {
                return NetworkInterface.NetworkInterfaceType == NetworkInterfaceType.MobileBroadbandGsm
                       || NetworkInterface.NetworkInterfaceType == NetworkInterfaceType.MobileBroadbandCdma;
            }
        }

        /// <summary>
        /// Returns the data connection currently used 
        /// </summary>
        public static MobileConnectionType ConnectionType
        {
            get 
            {
                if (IsWifiEnabled)
                    return MobileConnectionType.Wifi;
                else if (IsMobileBroadbandEnabled)
                    return MobileConnectionType.Wwan;
                else
                    return MobileConnectionType.Unknown;
            }
        }
    }
}
